<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/20
  Time: 20:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <span>
      <select id="AreaId" name="AreaId" size="1" class="sel">
           <option>-请选择地区-</option>
           <option value="1">北京</option>
           <option value="2">上海</option>
           <option value="3">深圳</option>
           <option value="3">浙江</option>
           <option value="3">广州</option>
           <option value="3">南宁</option>
           <option value="3">新疆</option>
       </select>

    <form>
        <input type="radio"  name ="fruit" value="苹果" checked>苹果
        <input type="radio"  name ="fruit" value="香蕉">香蕉
        <input type="radio"  name ="fruit" value="梨">梨
    </form>

    <form id="form1" name="form1" method="post" action="">
      <p><input type="checkbox" name="tree_id" value="我是1" />我是1</p>
      <p><input type="checkbox" name="tree_id" value="我是2" />我是2</p>
      <p><input type="checkbox" name="tree_id" value="我是3" />我是3</p>
      <p><input type="checkbox" name="tree_id" value="我是4" />我是4</p>

</form>


    <input type="button" value="点击" id="button_name" onclick="good()">
</span>
  <script>
      function good() {

              var name = document.getElementById("AreaId");
              var index = name.selectedIndex;
              var good = name.options[index].value;
              var value = name.options[index].text;
              //alert(good)
             // alert(value)


         // var obj = document.getElementsByTagName("input");
          var obj = document.getElementsByName("fruit");
          for(var i=0; i<obj.length; i ++){
              if(obj[i].checked){
                  var fruit=obj[i].value;
                 // alert(fruit);
              }
        }

          var tree=document.getElementsByName("tree_id");

          for(var i=0;i<tree.length;i++){
              if (tree[i].checked){
                  var good = tree[i].value;
                  //alert(good);
              }

          }

          //把json转换成字符串
          var jsonStr="{'name':'hello world'}";
          //lert("jsonStr:"+jsonStr);
          var good = eval("("+jsonStr+")");
          //alert("good:"+good.name);

          //测试
          var jsonObject={"name":"哈哈哈","age":12,"teach":function () {
              var name="非常不错";
             // alert(name);
              //alert("你好的！");
          }};

         // alert(jsonObject.name);
          //alert(jsonObject.age);
          //jsonObject.teach();




      }

  </script>
  </body>
</html>
